<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>轮播图--带标题动</title>
    <style>
         .banner{
            position: relative;
            width: 180px;
            height: 260px;
            /* margin: 0 auto; */
        }
        .btn-left{
            width: 40px;
            height: 40px;
            background: rgba(10, 10, 10, 0.5);
            color: #fff;
            text-align: center;
            line-height: 40px;
            border-top-right-radius: 20px;
            border-bottom-right-radius: 20px;
            position: absolute;
            top: 50%;
            margin-top: -20px;
        }
        .btn-right{
            width: 40px;
            height: 40px;
            background: rgba(10, 10, 10, 0.5);
            color: #fff;
            text-align: center;
            line-height: 40px;
            border-top-left-radius: 20px;
            border-bottom-left-radius: 20px;
            position: absolute;
            top: 50%;
            right: -46px;
            margin-top: -20px;
        }
        ul {
            list-style: none;
        }
       
    </style>
</head>
<body>
    <div class="ctr1">
        <button type="button">自动</button>
    </div>

    <div class="banner">
        <ul>
            <li><button class="btn btn-left" >&lt;</button></li>
            <li><button class="btn btn-right">&gt;</button></li>
            <li><img src="./images/1.jpg" alt=""></li>
        </ul>
    </div>


    <script>
        var btns = document.querySelectorAll('button')
        var pic = document.querySelector('img')
        var urls = ['./images/1.jpg','./images/2.jpg','./images/3.jpg','./images/4.jpg']
        var num = 0;

        pic.src=urls[num]
         var open = true
        btns[0].innerHTML="停留模式"
        btns[0].onclick=function(){
            if(open){
                open=false
                btns[0].innerHTML="循环模式"

            }else{
                open=true
                btns[0].innerHTML="停留模式"
            }
        }
        btns[1].onclick=function(){
            num--
            if(num<0){
                num=3
                pic.src=urls[num]
            }else{
                pic.src=urls[num]
            }
        }

        btns[2].onclick=function(){
            num++
            if(num>3){
                num=0
                pic.src=urls[num]
            }else{
                pic.src=urls[num]
            }
        }

    </script>
</body>
</html>